package xin.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import xin.entity.CommonResult;
import xin.entity.TOrgEmployee;
import xin.service.TOrgEmployeeService;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author young
 * @since 2023年10月09日
 */
@RestController
    @RequestMapping("/employ")
@Api(value = "员工",description = "这是员工接口")
public class TOrgEmployeeController {

    @Resource
    private TOrgEmployeeService tOrgEmployeeService;

    @ApiOperation(value = "查询所有员工信息")
    @GetMapping("/findAll")
    public CommonResult<?> findAll(){
        return CommonResult.success(this.tOrgEmployeeService.findAll(),"请求成功");
    }

    @PostMapping("/add")
    @ApiOperation(value = "添加员工信息")
    public CommonResult<?> add(@RequestBody TOrgEmployee tOrgEmployee){
        return this.tOrgEmployeeService.add(tOrgEmployee)>0?CommonResult.success(null,"添加成功"):CommonResult.error(null,"网络异常");
    }

    @PutMapping("/update")
    public CommonResult<?> update(@RequestBody TOrgEmployee tOrgEmployee){
        return this.tOrgEmployeeService.update(tOrgEmployee)>0?CommonResult.success(null,"修改成功"):CommonResult.error(null,"网络异常");
    }

    @GetMapping("/login")
    public CommonResult<?> login(String username,String password){
        return CommonResult.success(this.tOrgEmployeeService.login(username,password),"登录成功");
    }
}

